import axios from "axios";
import { IObjectKeys } from "./types";

const baseURL = import.meta.env.VITE_API_PATH as string;
const instance = axios.create({
    baseURL,
    timeout: 50000,
});

// 添加响应拦截器
instance.interceptors.response.use(function (response) {
    return response.data;
}, function (error) {
    return Promise.reject(error);
});

const fetch = {
    get(url: string, params: IObjectKeys) {
        return instance({
            method: 'get',
            url,
            params,
        })
    },

    post(url: string, data: IObjectKeys) {
        return instance({
            method: 'post',
            url,
            data,
        })
    }
}

export default fetch